package com.cloudbroker.bcs.platform.ltb.middle.util;

import com.cloudbroker.bcs.platform.ltb.bizapi.constants.type.UserType;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.base.vo.BrokerVO;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.market.vo.MarketVo;
import com.cloudbroker.bcs.platform.ltb.common.config.ConfigValues;
import com.cloudbroker.bcs.platform.ltb.common.util.SessionHelper;
import com.cloudbroker.bcs.platform.ltb.middle.entity.Market;
import com.cloudbroker.bcs.platform.ltb.middle.model.UserCache;
import com.hundsun.jres.common.util.UUID;

/**
 * Created by daibd19671 on 2016/8/20.
 */
public class MarketTokenUtil {

    public static final String MARKET_KEY = ".market_key";
    public static final String MARKET_NX = "market_nx";
    public static final int TIME = 24*60*60;
    /**
     * 获取行情token
     * */
    public static String getMarketToken(Market market){

        SessionHelper sessionHelper = SessionHelper.getInstance();
        String token = sessionHelper.getMarketToken(market.getCompany_id()+"."+market.getSendercomp_id()+MARKET_KEY);

        return token;
    }

    /**
     * 记录行情token到缓存
     * */
    public static String setMarketToken(Market market){
        String key = market.getCompany_id()+"."+market.getSendercomp_id() + MARKET_KEY;
        SessionHelper sessionHelper = SessionHelper.getInstance();
        sessionHelper.setInfoForSession(key,market.getMarket_token(),TIME);
        return market.getMarket_token();
    }

    /**
     * 获取行情token加锁
     * */
    public static Long getMarketLock(){
        SessionHelper sessionHelper = SessionHelper.getInstance();
        return sessionHelper.getMarketLock(MARKET_NX);
    }


    /**
     * 释放行情token锁
     * */
    public static void delMarketLock(){
        SessionHelper sessionHelper = SessionHelper.getInstance();
        sessionHelper.delMarketLock(MARKET_NX);
    }

}
